package com.elcl.support.versionupdate;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

import com.elcl.util.FileUtils;


/**
 * Created by lichunlin on 17/6/16.
 * 安装后删除安装包的广播接收器
 * 调用顺序为：ACTION_PACKAGE_REMOVED》》》ACTION_PACKAGE_ADDED》》》ACTION_PACKAGE_REPLACED
 * 因为：安装新包；要先删除原来的包，再add新的包，最后一个replace
 */

public class ApkInstallStateReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {//监听到安装的广播
            String packageNameInstall = intent.getDataString();//当前安装的应用包名
            String packageNameCurrent = context.getPackageName();//当前安装的应用包名

//            if (packageNameInstall.equals(packageNameCurrent)) {
            FileUtils.updateFile.delete();
            Toast.makeText(context, "安装包已删除", Toast.LENGTH_SHORT).show();
//            }
        }
        if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) {
        }

        if (Intent.ACTION_PACKAGE_REPLACED.equals(intent.getAction())) {

        }
    }
}
